package vip.liux.contracts.models.identity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.domain.Persistable;

/**
 * 用户的登录名及其关联的提供程序
 */
@Getter
@Setter
@Entity
@Table(name = "identity_user_logins", indexes = {
        @Index(name = "ix_identity_user_logins_login_provider_provider_key", columnList = "login_provider, provider_key")
})
public class IdentityUserLogin implements Persistable<IdentityUserLoginId> {
    @EmbeddedId
    private IdentityUserLoginId id;

    @ManyToOne
    @JoinColumn(name = "user_id", insertable = false, updatable = false)
    private IdentityUser user;
    /**
     * 租户ID
     */
    @Column(name = "tenant_id", length = 36)
    private String tenantId;

    /**
     * 登录提供者
     */
    @Column(name = "provider_key", nullable = false, length = 196)
    private String providerKey;

    /**
     * 提供者显示名称
     */
    @Column(name = "provider_display_name", length = 128)
    private String providerDisplayName;

    @JsonIgnore
    @Transient
    @Override
    public boolean isNew() {
        return id == null;
    }
}